<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="../error.jsp"%>

<%@page import="java.sql.Types"%>
<%@page import="df.jsp.Guard"%>
<%@page import="df.jsp.LabelMap"%>
<%@page import="df.jsp.Util"%>
<%@page import="df.bean.db.DBMgr"%>
<%@page import="df.bean.db.DataRecord"%>
<%@page import="df.bean.obj.util.JDate"%>
<%@page import="df.bean.obj.util.JNumber"%>
<%@ include file="../../_global.jsp" %>

<%
//
// Verify permission
//

            if (!Guard.checkPermission(session, Guard.PAGE_INPUT_GUARANTEE_DETAIL)) {
                response.sendRedirect("../message.jsp");
                return;
            }

//
// Initial LabelMap
//

            if (session.getAttribute("LANG_CODE") == null) {
                session.setAttribute("LANG_CODE", LabelMap.LANG_EN);
            }
            LabelMap labelMap = new LabelMap(session.getAttribute("LANG_CODE").toString());
            labelMap.add("TITLE_MAIN", "Guarantee Detail", "Guarantee Detail");
            labelMap.add("G_DR_CODE", "Doctor Code", "รหัสแพทย์");
            labelMap.add("GUARANTEE_CODE", "Guarantee Code", "รหัสการันตี");
            labelMap.add("G_TYPE_CODE", "Guarantee Type Code", "ประเภทการันตี");
            labelMap.add("ADMISSION", "Admisstion Type Code", "แผนกรับผู้ป่วย");
            labelMap.add("G_LOCATION", "Exclude Location", "สถานที่ไม่การันตี");
            labelMap.add("MM", "Month", "เดือน");
            labelMap.add("YYYY", "Year", "ปี");
            labelMap.add("START_DATE", "Start Date", "เริ่มวันที่");
            labelMap.add("START_TIME", "Start Time", "เริ่มเวลา");
            labelMap.add("EARLY_TIME", "Early Time", "Early Tiime");
            labelMap.add("END_DATE", "End Date", "ถึงวันที่");
            labelMap.add("END_TIME", "End Time", "ถึงเวลา");
            labelMap.add("LATE_TIME", "Late Time", "Late Time");
            labelMap.add("G_AMOUNT", "Guarantee Amount", "Guarantee Amount");
            labelMap.add("FIX_AMOUNT", "Fix Amount", "Fix Amount");
            labelMap.add("INCLUDE_AMOUNT", "Include Amount", "Include Amount");
            labelMap.add("EXCLUDE_AMOUNT", "Part Time Amount", "Part Time Amount");
            labelMap.add("OVER_ALLOCATE_PCT", "Over Guarantee Allocate", "ส่วนแบ่งเกินการันตี");
            labelMap.add("GUARANTEE_ALLOCATE_PCT", "In Guarantee Allocate", "ส่วนแบ่งในการันตี");

            labelMap.add("GUARANTEE_CHK_VERI", "Doctor Guarantee", "แพทย์การันตี");
            labelMap.add("GUARANTEE_CHK_DATE_TRUE","Yes","ใช่");
            labelMap.add("GUARANTEE_CHK_DATE_FALSE","No","ไม่ใช่");
            labelMap.add("ALERT_INVOICE", "INVOICE DATE ERROR", "วันที่ของ invoice date ไม่ถูกต้อง");
            labelMap.add("ABSORB_AMOUNT", "Absorb Amount", "จำนวนเงินเติมการันตี");
            labelMap.add("ABSORB_REMAIN_AMOUNT", "Absorb Remain", "จำนวนเติมการันตีคงเหลือ");

            request.setAttribute("labelMap", labelMap.getHashMap());
            
            //
            // Process request
            //

            request.setCharacterEncoding("UTF-8");
            
            byte MODE = DBMgr.MODE_INSERT;
            DataRecord stpGuaranteeRec = null, doctorRec = null, guaranteeTypeRec = null;
            DataRecord stpDelete = null;
            String MM = "", YYYY = "";

            
            if (request.getParameter("MODE") != null) {
                // Insert or update
                MODE = Byte.parseByte(request.getParameter("MODE"));

                stpGuaranteeRec = new DataRecord("STP_GUARANTEE");
                stpDelete = new DataRecord("STP_GUARANTEE");

                //, , , , , , , , 
                stpGuaranteeRec.addField("HOSPITAL_CODE", Types.VARCHAR, session.getAttribute("HOSPITAL_CODE").toString(), true);
                stpGuaranteeRec.addField("GUARANTEE_DR_CODE", Types.VARCHAR, request.getParameter("GUARANTEE_DR_CODE"), true);
                stpGuaranteeRec.addField("GUARANTEE_CODE", Types.VARCHAR, request.getParameter("GUARANTEE_CODE"), true);
                stpGuaranteeRec.addField("GUARANTEE_TYPE_CODE", Types.VARCHAR, request.getParameter("GUARANTEE_TYPE_CODE"), true);
                stpGuaranteeRec.addField("ADMISSION_TYPE_CODE", Types.VARCHAR, request.getParameter("ADMISSION_TYPE_CODE"), true);
                stpGuaranteeRec.addField("MM", Types.VARCHAR, request.getParameter("MM"), true);
                stpGuaranteeRec.addField("YYYY", Types.VARCHAR, request.getParameter("YYYY"), true);
                if("MLY".equalsIgnoreCase(request.getParameter("EDIT_GUARANTEE_TYPE_CODE"))){
                    stpGuaranteeRec.addField("START_DATE", Types.VARCHAR, JDate.saveDate(request.getParameter("START_DATE")), true);
                    stpGuaranteeRec.addField("START_TIME", Types.VARCHAR, JDate.saveTimeNOColon(request.getParameter("START_TIME")), true);
                    stpGuaranteeRec.addField("END_DATE", Types.VARCHAR, JDate.saveDate(request.getParameter("END_DATE")));
                    stpGuaranteeRec.addField("END_TIME", Types.VARCHAR,  JDate.saveTimeNOColon(request.getParameter("END_TIME")));
                }else{
                    stpGuaranteeRec.addField("START_DATE", Types.VARCHAR, JDate.saveDate(request.getParameter("START_DATE")), true);
                    stpGuaranteeRec.addField("START_TIME", Types.VARCHAR, JDate.saveTimeNOColon(request.getParameter("START_TIME")), true);
                    stpGuaranteeRec.addField("END_DATE", Types.VARCHAR, JDate.saveDate(request.getParameter("END_DATE")), true);
                    stpGuaranteeRec.addField("END_TIME", Types.VARCHAR,  JDate.saveTimeNOColon(request.getParameter("END_TIME")), true);
                }
                stpGuaranteeRec.addField("GUARANTEE_LOCATION", Types.VARCHAR, request.getParameter("GUARANTEE_LOCATION_CODE"));
				if(JDate.saveTime(request.getParameter("EARLY_TIME")) == ""){
					stpGuaranteeRec.addField("EARLY_TIME", Types.VARCHAR,  JDate.saveTime(request.getParameter("START_TIME")));
				}else{
					stpGuaranteeRec.addField("EARLY_TIME", Types.VARCHAR,  JDate.saveTime(request.getParameter("EARLY_TIME")));
				}
				if(JDate.saveTime(request.getParameter("LATE_TIME")) == ""){
					stpGuaranteeRec.addField("LATE_TIME", Types.VARCHAR,  JDate.saveTime(request.getParameter("END_TIME")));
				}else{
					stpGuaranteeRec.addField("LATE_TIME", Types.VARCHAR,  JDate.saveTime(request.getParameter("LATE_TIME")));
				}
                
                stpGuaranteeRec.addField("GUARANTEE_AMOUNT", Types.NUMERIC, JNumber.getSaveMoney(request.getParameter("GUARANTEE_AMOUNT")));
                stpGuaranteeRec.addField("GUARANTEE_FIX_AMOUNT", Types.NUMERIC, JNumber.getSaveMoney(request.getParameter("GUARANTEE_FIX_AMOUNT")));
                stpGuaranteeRec.addField("GUARANTEE_INCLUDE_AMOUNT", Types.NUMERIC, JNumber.getSaveMoney(request.getParameter("GUARANTEE_INCLUDE_AMOUNT")));
                stpGuaranteeRec.addField("GUARANTEE_EXCLUDE_AMOUNT", Types.NUMERIC, JNumber.getSaveMoney(request.getParameter("GUARANTEE_EXCLUDE_AMOUNT")));
                stpGuaranteeRec.addField("OVER_ALLOCATE_PCT", Types.NUMERIC, request.getParameter("OVER_ALLOCATE_PCT"));
                
                stpGuaranteeRec.addField("ACTIVE", Types.VARCHAR, request.getParameter("ACTIVE"));
                stpGuaranteeRec.addField("UPDATE_DATE", Types.VARCHAR, JDate.getDate());
                stpGuaranteeRec.addField("UPDATE_TIME", Types.VARCHAR, JDate.getTime());
                stpGuaranteeRec.addField("USER_ID", Types.VARCHAR, session.getAttribute("USER_ID").toString());

                if(1==1){
                	out.println(request.getParameter("GUARANTEE_CODE"));
                	//return;
                }
                if (MODE == DBMgr.MODE_INSERT) {
                    if (DBMgr.insertRecord(stpGuaranteeRec)) {
                        //REPLACE DATA
                        if("REPLACE".equalsIgnoreCase(request.getParameter("EDIT_MODE_INSERTUPDATE"))){
                            //session.setAttribute("MSG", labelMap.get(LabelMap.MSG_SAVE_FAIL));
                            if("MLY".equalsIgnoreCase(request.getParameter("EDIT_GUARANTEE_TYPE_CODE"))){
                                stpDelete.addField("HOSPITAL_CODE", Types.VARCHAR, session.getAttribute("HOSPITAL_CODE").toString(), true);
                                stpDelete.addField("GUARANTEE_DR_CODE", Types.VARCHAR, request.getParameter("EDIT_GUARANTEE_DR_CODE"), true);
                                stpDelete.addField("GUARANTEE_CODE", Types.VARCHAR, request.getParameter("EDIT_GUARANTEE_CODE"), true);
                                stpDelete.addField("GUARANTEE_TYPE_CODE", Types.VARCHAR, request.getParameter("EDIT_GUARANTEE_TYPE_CODE"), true);
                                stpDelete.addField("ADMISSION_TYPE_CODE", Types.VARCHAR, request.getParameter("EDIT_ADMISSION_TYPE_CODE"), true);
                                stpDelete.addField("START_DATE", Types.VARCHAR, request.getParameter("EDIT_START_DATE"), true);
                                stpDelete.addField("START_TIME", Types.VARCHAR, JDate.saveTimeNOColon(request.getParameter("EDIT_START_TIME")), true);
                                stpDelete.addField("MM", Types.VARCHAR, request.getParameter("EDIT_MM"), true);
                                stpDelete.addField("YYYY", Types.VARCHAR, request.getParameter("EDIT_YYYY"), true);
                                DBMgr.deleteRecord(stpDelete);
                            }else{
                                stpDelete.addField("HOSPITAL_CODE", Types.VARCHAR, session.getAttribute("HOSPITAL_CODE").toString(), true);
                                stpDelete.addField("GUARANTEE_DR_CODE", Types.VARCHAR, request.getParameter("EDIT_GUARANTEE_DR_CODE"), true);
                                stpDelete.addField("GUARANTEE_CODE", Types.VARCHAR, request.getParameter("EDIT_GUARANTEE_CODE"), true);
                                stpDelete.addField("GUARANTEE_TYPE_CODE", Types.VARCHAR, request.getParameter("EDIT_GUARANTEE_TYPE_CODE"), true);
                                stpDelete.addField("ADMISSION_TYPE_CODE", Types.VARCHAR, request.getParameter("EDIT_ADMISSION_TYPE_CODE"), true);
                                stpDelete.addField("MM", Types.VARCHAR, request.getParameter("EDIT_MM"), true);
                                stpDelete.addField("YYYY", Types.VARCHAR, request.getParameter("EDIT_YYYY"), true);
                                stpDelete.addField("START_DATE", Types.VARCHAR, request.getParameter("EDIT_START_DATE"), true);
                                stpDelete.addField("START_TIME", Types.VARCHAR, JDate.saveTimeNOColon(request.getParameter("EDIT_START_TIME")), true);
                                stpDelete.addField("END_DATE", Types.VARCHAR, request.getParameter("EDIT_END_DATE"), true);
                                stpDelete.addField("END_TIME", Types.VARCHAR,  JDate.saveTimeNOColon(request.getParameter("EDIT_END_TIME")), true);
                                DBMgr.deleteRecord(stpDelete);
                            }
                        }//if("REPLACE".equalsIgnoreCase(request.getParameter("EDIT_MODE_INSERTUPDATE")))
                        session.setAttribute("MSG", labelMap.get(LabelMap.MSG_SAVE_SUCCESS).replace("[HREF]", String.format("input/guarantee_main.jsp?GUARANTEE_DR_CODE=%1$s&MM=%2$s&YYYY=%3$s", stpGuaranteeRec.getField("GUARANTEE_DR_CODE").getValue(), stpGuaranteeRec.getField("MM").getValue(), stpGuaranteeRec.getField("YYYY").getValue())));
                    } 
                    else {
                        session.setAttribute("MSG", labelMap.get(LabelMap.MSG_SAVE_FAIL));
                    }
                } 
                else if (MODE == DBMgr.MODE_UPDATE) {
                    if (DBMgr.updateRecord(stpGuaranteeRec)) {
                        session.setAttribute("MSG", labelMap.get(LabelMap.MSG_SAVE_SUCCESS).replace("[HREF]", String.format("input/guarantee_main.jsp?GUARANTEE_DR_CODE=%1$s&MM=%2$s&YYYY=%3$s", stpGuaranteeRec.getField("GUARANTEE_DR_CODE").getValue(), stpGuaranteeRec.getField("MM").getValue(), stpGuaranteeRec.getField("YYYY").getValue())));
                    } 
                    else {
                        session.setAttribute("MSG", labelMap.get(LabelMap.MSG_SAVE_FAIL));
                    }
                }

                response.sendRedirect("../message.jsp");
                return;
            }
            else if (request.getParameter("GUARANTEE_DR_CODE") != null && request.getParameter("ADMISSION_TYPE_CODE") != null && request.getParameter("GUARANTEE_TYPE_CODE") != null && request.getParameter("MM") != null && request.getParameter("YYYY") != null && request.getParameter("START_DATE") != null && request.getParameter("START_TIME") != null && request.getParameter("END_DATE") != null && request.getParameter("END_TIME") != null) {
                // Edit
                MODE = DBMgr.MODE_UPDATE;
                
                String query = String.format("SELECT * FROM STP_GUARANTEE WHERE HOSPITAL_CODE = '%1$s' AND GUARANTEE_DR_CODE = '%2$s' AND ADMISSION_TYPE_CODE = '%3$s' AND GUARANTEE_TYPE_CODE = '%4$s' AND MM = '%5$s' AND YYYY = '%6$s' AND START_DATE = '%7$s' AND START_TIME = '%8$s' AND END_DATE = '%9$s' AND END_TIME = '%10$s' AND GUARANTEE_CODE='%11$s' ", session.getAttribute("HOSPITAL_CODE"), request.getParameter("GUARANTEE_DR_CODE"), request.getParameter("ADMISSION_TYPE_CODE"), request.getParameter("GUARANTEE_TYPE_CODE"), request.getParameter("MM"), request.getParameter("YYYY"), request.getParameter("START_DATE"), request.getParameter("START_TIME"), request.getParameter("END_DATE"), request.getParameter("END_TIME"), request.getParameter("GUARANTEE_CODE"));
                //out.println(query);
                stpGuaranteeRec = DBMgr.getRecord(query);

                doctorRec = DBMgr.getRecord(String.format("SELECT GUARANTEE_START_DATE,GUARANTEE_START_DATE,CODE, NAME_%1$s AS NAME, IN_GUARANTEE_PCT FROM DOCTOR WHERE CODE = '%2$s'", labelMap.getFieldLangSuffix(), DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_DR_CODE")));

                guaranteeTypeRec = DBMgr.getRecord(String.format("SELECT CODE, DESCRIPTION FROM GUARANTEE_TYPE WHERE CODE = '%1$s'", DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_TYPE_CODE")));
            }
            else if (request.getParameter("GUARANTEE_DR_CODE") != null && request.getParameter("MM") != null && request.getParameter("YYYY") != null) {
                // New
                MODE = DBMgr.MODE_INSERT;
                MM = request.getParameter("MM");
                YYYY = request.getParameter("YYYY");
                doctorRec = DBMgr.getRecord(String.format("SELECT GUARANTEE_START_DATE,GUARANTEE_START_DATE,OVER_GUARANTEE_PCT,CODE, NAME_%1$s AS NAME, IN_GUARANTEE_PCT FROM DOCTOR WHERE CODE = '%2$s'", labelMap.getFieldLangSuffix(), request.getParameter("GUARANTEE_DR_CODE")));
            }
            else {
                response.sendRedirect("../message.jsp");
            }
            //out.println(DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_TYPE_CODE"));
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>${labelMap.TITLE_MAIN}</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="../../css/share.css" media="all" />
        <link rel="stylesheet" type="text/css" href="../../css/calendar.css" />
        <script type="text/javascript" src="../../javascript/calendar.js"></script>
        <script type="text/javascript" src="../../javascript/ajax.js"></script>
        <script type="text/javascript" src="../../javascript/util.js"></script>
        <script type="text/javascript" src="../../javascript/search_form.js"></script>
        <script type="text/javascript">
            var TYPE_CODE_CHECK = "MLY";
            var TYPE_CODE_CHECK_STP = "STP";
            function GUARANTEE_TYPE_CODE_KeyPress(e) {
                var key = window.event ? window.event.keyCode : e.which;    // ? IE : Firefox

                if (key == 13) {
                    document.mainForm.GUARANTEE_TYPE_CODE.blur();
                    return false;
                }
                else {
                    return true;
                }
            }
            
            function AJAX_Refresh_GUARANTEE_TYPE() {
                var target = "../../RetrieveData?TABLE=GUARANTEE_TYPE&COND=CODE='" + document.mainForm.GUARANTEE_TYPE_CODE.value +"'";
                AJAX_Request(target, AJAX_Handle_Refresh_GUARANTEE_TYPE);
            }
            
            function AJAX_Handle_Refresh_GUARANTEE_TYPE() {
                if (AJAX_IsComplete()) {
                    var xmlDoc = AJAX.responseXML;

                    if (!isXMLNodeExist(xmlDoc, "CODE")) {
                        document.mainForm.GUARANTEE_TYPE_CODE.value = "";
                        document.mainForm.GUARANTEE_TYPE_DESCRIPTION.value = "";
                        return;
                    }
                    
                    // Data found
                    document.mainForm.GUARANTEE_TYPE_DESCRIPTION.value = getXMLNodeValue(xmlDoc, "DESCRIPTION");
                }
            }

            //GUARANTEE_LOCATION
            //GUARANTEE_LOCATION_CODE_KeyPress
           
            function GUARANTEE_LOCATION_CODE_KeyPress(e) {

                 var key = window.event ? window.event.keyCode : e.which;    // ? IE : Firefox

                if (key == 13) {
                    document.mainForm.GUARANTEE_LOCATION_CODE.blur();
                    return false;
                }
                else {
                    return true;
                }
            }

            function AJAX_Refresh_GUARANTEE_LOCATION() {
                var target = "../../RetrieveData?TABLE=LOCATION&COND=CODE='" + document.mainForm.GUARANTEE_LOCATION_CODE.value +"'";
                AJAX_Request(target, AJAX_Handle_Refresh_GUARANTEE_LOCATION);
            }
            
            function AJAX_Handle_Refresh_GUARANTEE_LOCATION() {
                if (AJAX_IsComplete()) {
                    var xmlDoc = AJAX.responseXML;
                    
                    if (!isXMLNodeExist(xmlDoc, "CODE")) {
                        //alert("AJAX_Handle_Refresh_GUARANTEE_LOCATION");
                        document.mainForm.GUARANTEE_LOCATION_CODE.value = "";
                        document.mainForm.GUARANTEE_LOCATION_DESCRIPTION.value = "";
                        return;
                    }
                    
                    // Data found
                    document.mainForm.GUARANTEE_LOCATION_DESCRIPTION.value = getXMLNodeValue(xmlDoc, "DESCRIPTION");
                }
            }            
            
            function AJAX_VerifyData() {
                //alert("2");
                var guacode = document.mainForm.GUARANTEE_CODE;
                var type_code = document.mainForm.GUARANTEE_TYPE_CODE.value;
                var con = "";
                if(type_code==TYPE_CODE_CHECK){
                    if(guacode.value != ""){
                        con = " AND GUARANTEE_CODE='" + document.mainForm.GUARANTEE_CODE.value + "'"
                        + " AND START_DATE='" + toSaveDate(document.mainForm.START_DATE.value) + "'"
                        + " AND START_TIME='" + toSaveTimeNOColon(document.mainForm.START_TIME.value) + "'"
                        + " AND END_DATE='" + toSaveDate(document.mainForm.END_DATE.value) + "'"
                        + " AND END_TIME='" + toSaveTimeNOColon(document.mainForm.END_TIME.value) + "'";
                    }else{
                        con = " AND GUARANTEE_CODE='" + document.mainForm.GUARANTEE_CODE.value + "'"
                        + " AND START_DATE='" + toSaveDate(document.mainForm.START_DATE.value) + "'"
                        + " AND START_TIME='" + toSaveTimeNOColon(document.mainForm.START_TIME.value) + "'"
                        + " AND END_DATE='" + toSaveDate(document.mainForm.END_DATE.value) + "'"
                        + " AND END_TIME='" + toSaveTimeNOColon(document.mainForm.END_TIME.value) + "'";
                    }
                }else{
                    if(guacode.value != ""){
                        con = " AND GUARANTEE_CODE='" + document.mainForm.GUARANTEE_CODE.value + "'"
                            + " AND START_DATE='" + toSaveDate(document.mainForm.START_DATE.value) + "'"
                            + " AND START_TIME='" + toSaveTimeNOColon(document.mainForm.START_TIME.value) + "'"
                            + " AND END_DATE='" + toSaveDate(document.mainForm.END_DATE.value) + "'"
                            + " AND END_TIME='" + toSaveTimeNOColon(document.mainForm.END_TIME.value) + "'";
                    }else{
                        con = " AND GUARANTEE_CODE='" + toSaveDate(document.mainForm.START_DATE.value) + toSaveTimeNOColon(document.mainForm.START_TIME.value) + "'"
                            + " AND START_DATE='" + toSaveDate(document.mainForm.START_DATE.value) + "'"
                            + " AND START_TIME='" + toSaveTimeNOColon(document.mainForm.START_TIME.value) + "'"
                            + " AND END_DATE='" + toSaveDate(document.mainForm.END_DATE.value) + "'"
                            + " AND END_TIME='" + toSaveTimeNOColon(document.mainForm.END_TIME.value) + "'";
                    }
                }
                
                var target = "../../RetrieveData?TABLE=STP_GUARANTEE&COND=HOSPITAL_CODE='<%=session.getAttribute("HOSPITAL_CODE")%>'"
                    + " AND GUARANTEE_DR_CODE='" + document.mainForm.GUARANTEE_DR_CODE.value + "'"
                    + con
                    + " AND GUARANTEE_TYPE_CODE='" + document.mainForm.GUARANTEE_TYPE_CODE.value + "'"
                    + " AND ADMISSION_TYPE_CODE='" + document.mainForm.ADMISSION_TYPE_CODE.value + "'"
                    + " AND YYYY='" + document.mainForm.YYYY.value + "'"
                    + " AND MM='" + document.mainForm.MM.value + "'";


                //document.mainForm.showsql.value = target;
                //alert(type_code);
                AJAX_Request(target, AJAX_Handle_VerifyData);
            }
            
            function AJAX_Handle_VerifyData() {
                if (AJAX_IsComplete()) {
                    var xmlDoc = AJAX.responseXML;

                    var beExist = isXMLNodeExist(xmlDoc, "HOSPITAL_CODE");
                    switch (document.mainForm.MODE.value) {
                    case "<%=DBMgr.MODE_INSERT%>" :
                            var type_code = document.mainForm.GUARANTEE_TYPE_CODE.value;
                            if(type_code==TYPE_CODE_CHECK || type_code==TYPE_CODE_CHECK_STP){
                                document.mainForm.GUARANTEE_CODE.value = document.mainForm.YYYY.value + document.mainForm.MM.value;
                            }else{
                                document.mainForm.GUARANTEE_CODE.value = toSaveDate(document.mainForm.START_DATE.value) + toSaveTimeNOColon(document.mainForm.START_TIME.value);
                            }

                            if (beExist) {
                                //alert('New INSERT-insert');
                                if (confirm("<%=labelMap.get("CONFIRM_REPLACE_DATA")%>")) {
                                    document.mainForm.MODE.value= "<%=DBMgr.MODE_UPDATE%>";
                                    document.mainForm.submit();
                                }else if (confirm("<%=labelMap.get(LabelMap.CONFIRM_ADD_NEW_DATA)%>")) {
                                    document.mainForm.MODE.value= "<%=DBMgr.MODE_INSERT%>";
                                    document.mainForm.submit();
                            }
                            }
                            else {
                                document.mainForm.submit();
                            }
                        break;
                    case "<%=DBMgr.MODE_UPDATE%>" :
                        if (beExist) {
                            if(chekcUpdateInsertPK()){
                                //Update Record - PK No Edit
                                document.mainForm.submit();
                            }else{
                                //Error - PK duplicate in Database
                                alert('Duplicate Data');
                            }
                        }
                        else {
                        	var type_code = document.mainForm.GUARANTEE_TYPE_CODE.value;
                        	if(type_code=="MLY"){
                               	document.mainForm.GUARANTEE_CODE.value = document.mainForm.YYYY.value + document.mainForm.MM.value;
                            }else{
                               	document.mainForm.GUARANTEE_CODE.value = toSaveDate(document.mainForm.START_DATE.value) + toSaveTimeNOColon(document.mainForm.START_TIME.value);
                            }
                            if (confirm("<%=labelMap.get("CONFIRM_REPLACE_DATA")%>")) {
                                //Delete Record, Update Record - PK Edit
                                document.mainForm.EDIT_MODE_INSERTUPDATE.value = "REPLACE";
                                document.mainForm.MODE.value= "<%=DBMgr.MODE_INSERT%>";
                                document.mainForm.submit();
                            }else if (confirm("<%=labelMap.get(LabelMap.CONFIRM_ADD_NEW_DATA)%>")) {
                                document.mainForm.MODE.value= "<%=DBMgr.MODE_INSERT%>";
                                document.mainForm.submit();
                            }
                        }
                        break;
                    }
                }
            }
            
            function chekcUpdateInsertPK(){
                var type_code = document.mainForm.GUARANTEE_TYPE_CODE.value;
                if(type_code==TYPE_CODE_CHECK){
                    if((document.mainForm.EDIT_GUARANTEE_DR_CODE.value == document.mainForm.GUARANTEE_DR_CODE.value)
                            && (document.mainForm.EDIT_GUARANTEE_DR_CODE.value == document.mainForm.GUARANTEE_DR_CODE.value)
                            && (document.mainForm.EDIT_GUARANTEE_CODE.value == document.mainForm.GUARANTEE_CODE.value)
                            && (document.mainForm.EDIT_GUARANTEE_TYPE_CODE.value == document.mainForm.GUARANTEE_TYPE_CODE.value)
                            && (document.mainForm.EDIT_ADMISSION_TYPE_CODE.value == document.mainForm.ADMISSION_TYPE_CODE.value)
                            && (document.mainForm.EDIT_MM.value == document.mainForm.MM.value)
                            && (document.mainForm.EDIT_YYYY.value == document.mainForm.YYYY.value)
                            && (document.mainForm.EDIT_START_DATE.value == toSaveDate(document.mainForm.START_DATE.value))
                            && (document.mainForm.EDIT_START_TIME.value == toSaveTimeNOColon(document.mainForm.START_TIME.value))
                            && (document.mainForm.EDIT_END_DATE.value == toSaveDate(document.mainForm.END_DATE.value))
                            && (document.mainForm.EDIT_END_TIME.value == toSaveTimeNOColon(document.mainForm.END_TIME.value))                            
                        ){
                        return true;
                    }else{
                        return false;
                    }
                }else{
                    if((document.mainForm.EDIT_GUARANTEE_DR_CODE.value == document.mainForm.GUARANTEE_DR_CODE.value)
                            && (document.mainForm.EDIT_GUARANTEE_DR_CODE.value == document.mainForm.GUARANTEE_DR_CODE.value)
                            && (document.mainForm.EDIT_GUARANTEE_CODE.value == document.mainForm.GUARANTEE_CODE.value)
                            && (document.mainForm.EDIT_GUARANTEE_TYPE_CODE.value == document.mainForm.GUARANTEE_TYPE_CODE.value)
                            && (document.mainForm.EDIT_ADMISSION_TYPE_CODE.value == document.mainForm.ADMISSION_TYPE_CODE.value)
                            && (document.mainForm.EDIT_MM.value == document.mainForm.MM.value)
                            && (document.mainForm.EDIT_YYYY.value == document.mainForm.YYYY.value)
                            && (document.mainForm.EDIT_START_DATE.value == toSaveDate(document.mainForm.START_DATE.value))
                            && (document.mainForm.EDIT_START_TIME.value == toSaveTimeNOColon(document.mainForm.START_TIME.value))
                            && (document.mainForm.EDIT_END_DATE.value == toSaveDate(document.mainForm.END_DATE.value))
                            && (document.mainForm.EDIT_END_TIME.value == toSaveTimeNOColon(document.mainForm.END_TIME.value))
                        ){
                        return true;
                    }else{
                        return false;
                    }
                }
            }
            //  !isObjectEmptyString(document.mainForm.GUARANTEE_CODE, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') && 
            function SAVE_Click() {
                if (!isObjectEmptyString(document.mainForm.GUARANTEE_DR_CODE, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') && 
                    !isObjectEmptyString(document.mainForm.MM, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') && 
                    !isObjectEmptyString(document.mainForm.YYYY, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') && 
                    !isObjectEmptyString(document.mainForm.GUARANTEE_TYPE_CODE, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') && 
                    !isObjectEmptyString(document.mainForm.ADMISSION_TYPE_CODE, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') && 
                    !isObjectEmptyString(document.mainForm.START_DATE, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') && 
                    isObjectValidDate(document.mainForm.START_DATE, '<%=labelMap.get(LabelMap.ALERT_INVALID_DATE)%>') && 
                    !isObjectEmptyString(document.mainForm.END_DATE, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') && 
                    isObjectValidDate(document.mainForm.END_DATE, '<%=labelMap.get(LabelMap.ALERT_INVALID_DATE)%>') && 
                    !isObjectEmptyString(document.mainForm.START_TIME, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') &&
                    //isObjectValidTime(document.mainForm.START_TIME, '<%=labelMap.get(LabelMap.ALERT_INVALID_TIME)%>') && 
                    !isObjectEmptyString(document.mainForm.END_TIME, '<%=labelMap.get(LabelMap.ALERT_REQUIRED_FIELD)%>') &&
                    //isObjectValidTime(document.mainForm.END_TIME, '<%=labelMap.get(LabelMap.ALERT_INVALID_TIME)%>') && 
                    isObjectValidTime(document.mainForm.EARLY_TIME, '<%=labelMap.get(LabelMap.ALERT_INVALID_TIME)%>') && 
                    isObjectValidTime(document.mainForm.LATE_TIME, '<%=labelMap.get(LabelMap.ALERT_INVALID_TIME)%>') && 
                    //isObjectValidNumber(document.mainForm.GUARANTEE_AMOUNT, '<%=labelMap.get(LabelMap.ALERT_INVALID_NUMBER)%>') && 
                    //isObjectValidNumber(document.mainForm.GUARANTEE_FIX_AMOUNT, '<%=labelMap.get(LabelMap.ALERT_INVALID_NUMBER)%>') && 
                    //isObjectValidNumber(document.mainForm.GUARANTEE_INCLUDE_AMOUNT, '<%=labelMap.get(LabelMap.ALERT_INVALID_NUMBER)%>') && 
                    //isObjectValidNumber(document.mainForm.GUARANTEE_EXCLUDE_AMOUNT, '<%=labelMap.get(LabelMap.ALERT_INVALID_NUMBER)%>') && 
                    isObjectValidNumber(document.mainForm.OVER_ALLOCATE_PCT, '<%=labelMap.get(LabelMap.ALERT_INVALID_NUMBER)%>')) {
					AJAX_VerifyData();
                }
            }

            // Check data on table SUMMARY_MONTHLY : 2009-07-01 By Nop
            function AJAX_Verify_Check_Summary_Monthly() {
                var date_input = "00/" + document.mainForm.MM.value + "/" + document.mainForm.YYYY.value;
                var target = "../../CheckSummaryMonthlySrvl?DATE_INPUT=" + date_input + "";
                AJAX_Request(target, AJAX_Handle_Verify_Check_Summary_Monthly);
            }  

            function AJAX_Handle_Verify_Check_Summary_Monthly(){
                if (AJAX_IsComplete()) {
                    var xmlDoc = AJAX.responseXML;
                    //alert(getXMLNodeValue(xmlDoc, "STATUS"));
                    if (getXMLNodeValue(xmlDoc, "STATUS")=='YES') {
                        //alert('<%=labelMap.get("ALERT_INVOICE")%>');
                        document.mainForm.SAVE.disabled = true;
                    }else{
                    	document.mainForm.SAVE.disabled = false;
                    }
                }				
           	}

           	//+++++++++++++++++++++++++++++++++++++++ 20090819
           	function chkStepSharing(){
           	}
        </script>
        <style type="text/css">
<!--
.style1 {color: #003399}
-->
        </style>
</head>    
    <body onload="AJAX_Verify_Check_Summary_Monthly();">
        <form id="mainForm" name="mainForm" method="post" action="guarantee_detail.jsp">
            
            <input type="hidden" size="50" id="EDIT_MODE_INSERTUPDATE" name="EDIT_MODE_INSERTUPDATE" value="" /><br/>
            <input type="hidden" size="50" id="EDIT_HOSPITAL_CODE" name="EDIT_HOSPITAL_CODE" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "HOSPITAL_CODE") %>" />
            
            <input type="hidden" size="50" id="EDIT_GUARANTEE_DR_CODE" name="EDIT_GUARANTEE_DR_CODE" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_DR_CODE") %>" />
            <input type="hidden" size="50" id="EDIT_GUARANTEE_CODE" name="EDIT_GUARANTEE_CODE" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_CODE") %>" />
            <input type="hidden" size="50" id="EDIT_GUARANTEE_TYPE_CODE" name="EDIT_GUARANTEE_TYPE_CODE" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_TYPE_CODE") %>" />
            <input type="hidden" size="50" id="EDIT_ADMISSION_TYPE_CODE" name="EDIT_ADMISSION_TYPE_CODE" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "ADMISSION_TYPE_CODE") %>" />
            <input type="hidden" size="50" id="EDIT_MM" name="EDIT_MM" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "MM") %>" />
            <input type="hidden" size="50" id="EDIT_YYYY" name="EDIT_YYYY" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "YYYY") %>" />
            <input type="hidden" size="50" id="EDIT_START_DATE" name="EDIT_START_DATE" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "START_DATE") %>" />
            <input type="hidden" size="50" id="EDIT_START_TIME" name="EDIT_START_TIME" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "START_TIME") %>" />
            <input type="hidden" size="50" id="EDIT_END_DATE" name="EDIT_END_DATE" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "END_DATE") %>" />
            <input type="hidden" size="50" id="EDIT_END_TIME" name="EDIT_END_TIME" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "END_TIME") %>" />
            
            <input type="hidden" id="MODE" name="MODE" value="<%= MODE %>" />
            <table class="form">
                <tr><th colspan="4">
                        <div style="float: left;">${labelMap.TITLE_MAIN}</div>
				</th></tr>
                <tr>
                    <td class="label">
                        <label for="GUARANTEE_DR_CODE"><span class="style1">${labelMap.G_DR_CODE} *</span></label>                    </td>
                    <td class="input" colspan="3">
                        <input type="text" id="GUARANTEE_DR_CODE" name="GUARANTEE_DR_CODE" class="short" readonly="readonly" value="<%= DBMgr.getRecordValue(doctorRec, "CODE") %>" />
                        <input type="text" id="GUARANTEE_DR_NAME" name="GUARANTEE_DR_NAME" class="mediumMax" readonly="readonly" value="<%= DBMgr.getRecordValue(doctorRec, "NAME") %>" />                    </td>
                </tr>
                <tr>
                  <td class="label">
                    <label for="MM"><span class="style1">${labelMap.MM} *</span></label>                    </td>
                    <td class="input">
                        <input type="text" id="MM" name="MM" class="short" value="<%= stpGuaranteeRec == null ? MM : DBMgr.getRecordValue(stpGuaranteeRec, "MM") %>" readonly="readonly" />                    </td>
                  <td class="label">
                    <label for="YYYY"><span class="style1">${labelMap.YYYY}*</span></label>                    </td>
                    <td class="input">
                        <input type="text" id="YYYY" name="YYYY" class="short" value="<%= stpGuaranteeRec == null ? YYYY : DBMgr.getRecordValue(stpGuaranteeRec, "YYYY") %>" readonly="readonly" />                    </td>
                </tr>
                <input type="hidden" name="GUARANTEE_CODE" value="<%=DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_CODE")%>">
                <!--tr>
                    <td class="labelRequest">
                        <label for="GUARANTEE_CODE">${labelMap.GUARANTEE_CODE} *</label>
                    </td>
                    <td class="input" colspan="3">
                        <input type="text" id="GUARANTEE_CODE" name="GUARANTEE_CODE" class="medium" value="<%= DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_CODE") %>" maxlength="20" />
                    </td>
                </tr-->
                <tr>
                    <td class="labelRequest"><label for="GUARANTEE_TYPE_CODE">${labelMap.G_TYPE_CODE} *</label></td>
					<td colspan="3" class="input">
                        <%= DBMgr.generateDropDownList("GUARANTEE_TYPE_CODE", "medium", "inActive", "SELECT CODE, DESCRIPTION, ACTIVE FROM GUARANTEE_TYPE ORDER BY DESCRIPTION", "DESCRIPTION", "CODE", DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_TYPE_CODE")) %>                    </td>
				</tr>
                <tr>
                    <td class="labelRequest"><label for="ADMISSION_TYPE_CODE">${labelMap.ADMISSION} *</label></td>
                    <td colspan="3" class="input">
						<select id="ADMISSION_TYPE_CODE" name="ADMISSION_TYPE_CODE" class="short">
							<option value="U" <%= DBMgr.getRecordValue(stpGuaranteeRec, "ADMISSION_TYPE_CODE").equalsIgnoreCase("U") ? " selected=\"selected\"" : "" %>>ALL</option>
                            <option value="I" <%= DBMgr.getRecordValue(stpGuaranteeRec, "ADMISSION_TYPE_CODE").equalsIgnoreCase("I") ? " selected=\"selected\"" : "" %>>IPD</option>
                            <option value="O" <%= DBMgr.getRecordValue(stpGuaranteeRec, "ADMISSION_TYPE_CODE").equalsIgnoreCase("O") ? " selected=\"selected\"" : "" %>>OPD</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="label">
                        <label for="GAURANTEE_LOCATION">${labelMap.G_LOCATION}</label>                    </td>
                    <td class="input" colspan="3">
                        <input name="GUARANTEE_LOCATION_CODE" type="text" class="short" id="GUARANTEE_LOCATION_CODE" onblur="AJAX_Refresh_GUARANTEE_LOCATION();" onkeypress="return GUARANTEE_LOCATION_CODE_KeyPress(event);" value="<%= DBMgr.getRecordValue(guaranteeTypeRec, "GUARANTEE_LOCATION") %>" maxlength="20" />
                        <input id="SEARCH_GUARANTEE_LOCATION_CODE" name="SEARCH_GUARANTEE_LOCATION_CODE" type="image" class="image_button" src="../../images/search_button.png" alt="Search" onclick="openSearchForm('../search.jsp?TABLE=LOCATION&TARGET=GUARANTEE_LOCATION_CODE&DISPLAY_FIELD=DESCRIPTION&BEACTIVE=1&HANDLE=AJAX_Refresh_GUARANTEE_LOCATION'); return false;" />
                        <input type="text" id="GUARANTEE_LOCATION_DESCRIPTION" name="GUARANTEE_LOCATION_DESCRIPTION" class="mediumMax" readonly="readonly" value="<%= DBMgr.getRecordValue(guaranteeTypeRec, "GUARANTEE_LOCATION") %>" />                    </td>
                </tr>
                <tr>
                  <td class="label">
                    <label for="START_DATE"><span class="style1">${labelMap.START_DATE} *</span></label>                    </td>
                    <td class="input">
                        <input name="START_DATE" type="text" class="short" id="START_DATE" maxlength="10" value="<%= JDate.showDate(DBMgr.getRecordValue(stpGuaranteeRec, "START_DATE"))%>" onblur="CheckDate(this.value,'START_DATE','END_DATE')" />
                        <input type="image" class="image_button" src="../../images/calendar_button.png" alt="" onclick="displayDatePicker('START_DATE'); return false;" />
                        DD/MM/YYYY                    </td>
                    <td class="labelRequest">
                        <label for="END_DATE">${labelMap.END_DATE}*</label>                    </td>
                    <td class="input">
                        <input name="END_DATE" type="text" class="short" id="END_DATE" value="<%= JDate.showDate(DBMgr.getRecordValue(stpGuaranteeRec, "END_DATE"))%>" />
                        <input type="image" class="image_button" src="../../images/calendar_button.png" alt="" onclick="displayDatePicker('END_DATE'); return false;" />
                        DD/MM/YYYY                    </td>
                </tr>
                <tr>
                  <td class="label">
                    <label for="START_TIME"><span class="style1">${labelMap.START_TIME} *</span></label>                    </td>
                    <td class="input">
                        <input name="START_TIME" type="text" class="short" id="START_TIME" maxlength="4" value="<%= JDate.showTime(DBMgr.getRecordValue(stpGuaranteeRec, "START_TIME")) %>" onblur="return checkKeyTime(this);" />
                        HHMM</td>
                    <td class="labelRequest">
                        <label for="bText">${labelMap.END_TIME}*</label>                    </td>
                    <td class="input">
                        <input name="END_TIME" type="text" class="short" id="END_TIME" maxlength="4" value="<%= JDate.showTime(DBMgr.getRecordValue(stpGuaranteeRec, "END_TIME")) %>"  onblur="return checkKeyTime(this);" />
                        HHMM</td>
                </tr>
                <tr>
                    <td class="label">
                    <label for="START_TIME">${labelMap.EARLY_TIME}</label>                    </td>
                    <td class="input"><input name="EARLY_TIME" type="text" class="short" id="EARLY_TIME" maxlength="4" value="<%= JDate.showTime(DBMgr.getRecordValue(stpGuaranteeRec, "EARLY_TIME")) %>"  onblur="return checkKeyTime(this);" /> HHMM</td>
                    <td class="label">
                        <label for="bText">${labelMap.LATE_TIME}</label>                    </td>
                    <td class="input">
                        <input name="LATE_TIME" type="text" class="short" id="LATE_TIME" maxlength="4" value="<%= JDate.showTime(DBMgr.getRecordValue(stpGuaranteeRec, "LATE_TIME")) %>"  onblur="return checkKeyTime(this);" /> HHMM</td>
                </tr>
                <tr>
                    <td class="label">
                        <label for="GUARANTEE_AMOUNT">${labelMap.G_AMOUNT}</label>                    </td>
                    <td class="input">
                        <input name="GUARANTEE_AMOUNT" type="text" class="short alignRight" id="GUARANTEE_AMOUNT" maxlength="13" value="<%= JNumber.getShowMoney(Double.parseDouble(DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_AMOUNT").equalsIgnoreCase("") ? "0" : DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_AMOUNT") )) %>" /></td>
                    <td class="label">
                        <label for="GUARANTEE_FIX_AMOUNT">${labelMap.FIX_AMOUNT}</label>                    </td>
                    <td class="input">
                        <input name="GUARANTEE_FIX_AMOUNT" type="text" class="short alignRight" id="GUARANTEE_FIX_AMOUNT" maxlength="13" value="<%= JNumber.getShowMoney(Double.parseDouble(DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_FIX_AMOUNT").equalsIgnoreCase("") ? "0" : DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_FIX_AMOUNT") )) %>" /></td>
                </tr>
                <tr>
                    <td class="label">
                        <label for="GUARANTEE_INCLUDE_AMOUNT">${labelMap.INCLUDE_AMOUNT}</label>                    </td>
                    <td class="input">
                        <input name="GUARANTEE_INCLUDE_AMOUNT" type="text" class="short alignRight" id="GUARANTEE_INCLUDE_AMOUNT" maxlength="13" value="<%= JNumber.getShowMoney(Double.parseDouble(DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_INCLUDE_AMOUNT").equalsIgnoreCase("") ? "0" : DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_INCLUDE_AMOUNT") )) %>" /></td>
                    <td class="label">
                        <label for="GUARANTEE_EXCLUDE_AMOUNT">${labelMap.EXCLUDE_AMOUNT}</label>                    </td>
                    <td class="input">
                        <input name="GUARANTEE_EXCLUDE_AMOUNT" type="text" class="short alignRight" id="GUARANTEE_EXCLUDE_AMOUNT" maxlength="13" value="<%= JNumber.getShowMoney(Double.parseDouble(DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_EXCLUDE_AMOUNT").equalsIgnoreCase("") ? "0" : DBMgr.getRecordValue(stpGuaranteeRec, "GUARANTEE_EXCLUDE_AMOUNT") )) %>" /></td>
                </tr>
                <!-- 
                <tr>
                    <td class="label">
                        <label for="ALLOCATE_PCT">${labelMap.GUARANTEE_CHK_VERI}</label>                    </td>
                    <td class="input" colspan="3">
                        <%
                            if(DBMgr.getRecordValue(doctorRec, "GUARANTEE_START_DATE")!="" && DBMgr.getRecordValue(doctorRec, "GUARANTEE_START_DATE")!=""){
                                %>${labelMap.GUARANTEE_CHK_DATE_TRUE}<%
                            }else{
                                %>${labelMap.GUARANTEE_CHK_DATE_FALSE}<%
                            }
                        %>                    </td>
                </tr>
                -->
                <tr>
                    <td class="label"> 
                        <label for="GUARANTEE_ALLOCATE_PCT">${labelMap.GUARANTEE_ALLOCATE_PCT}</label>                    </td>
                    <td class="input">
                        <input name="GUARANTEE_ALLOCATE_PCT" type="text" class="short alignRight" id="GUARANTEE_ALLOCATE_PCT" maxlength="13" value="<%= DBMgr.getRecordValue(doctorRec, "IN_GUARANTEE_PCT") %>" /></td>                                   
                    <td class="label">
                        <label for="ALLOCATE_PCT">${labelMap.OVER_ALLOCATE_PCT}</label>                    </td>
                    <td class="input">
                        <input name="OVER_ALLOCATE_PCT" type="text" class="short alignRight" id="OVER_ALLOCATE_PCT" maxlength="13" value="<%= DBMgr.getRecordValue(doctorRec, "OVER_GUARANTEE_PCT") %>" /></td>
                </tr>
                <tr>
                    <td class="label">
                        <label for="ABSORB_AMOUNT">${labelMap.ABSORB_AMOUNT}</label>                    </td>
                    <td class="input">
                        <input name="ABSORB_AMOUNT" type="text" class="short alignRight" readonly="readonly" id="ABSORB_AMOUNT" maxlength="13" value="<%= JNumber.getShowMoney(Double.parseDouble(DBMgr.getRecordValue(stpGuaranteeRec, "HP402_ABSORB_AMOUNT").equalsIgnoreCase("") ? "0" : DBMgr.getRecordValue(stpGuaranteeRec, "HP402_ABSORB_AMOUNT"))) %>" /> Baht</td>
                    <td class="label">
                        <label for="ABSORB_REMAIN_AMOUNT">${labelMap.ABSORB_REMAIN_AMOUNT}</label>                    </td>
                    <td class="input">
                        <input name="ABSORB_REMAIN_AMOUNT" type="text" class="short alignRight" readonly="readonly" id="ABSORB_REMAIN_AMOUNT" maxlength="13" value="<%= JNumber.getShowMoney(Double.parseDouble(DBMgr.getRecordValue(stpGuaranteeRec, "DF_ABSORB_AMOUNT").equalsIgnoreCase("") ? "0" : DBMgr.getRecordValue(stpGuaranteeRec, "DF_ABSORB_AMOUNT"))) %>" /> Baht</td>
                </tr>
                <tr>
                	<td class="label"><label for="ACTIVE_1">${labelMap.ACTIVE}</label></td> 
                    <td class="input" colspan="3">
                        <input type="radio" id="ACTIVE_1" name="ACTIVE" value="1"<%= DBMgr.getRecordValue(stpGuaranteeRec, "ACTIVE").equalsIgnoreCase("1") || DBMgr.getRecordValue(stpGuaranteeRec, "ACTIVE").equalsIgnoreCase("") ? " checked=\"checked\"" : ""%> />
                        <label for="ACTIVE_1">${labelMap.ACTIVE_1}</label>
                        <input type="radio" id="ACTIVE_0" name="ACTIVE" value="0"<%= DBMgr.getRecordValue(stpGuaranteeRec, "ACTIVE").equalsIgnoreCase("0") ? " checked=\"checked\"" : ""%> />
                        <label for="ACTIVE_0">${labelMap.ACTIVE_0}</label>                    </td>
                </tr>
                <tr>
                    <th colspan="4" class="buttonBar">                        
                        <input type="button" id="SAVE" name="SAVE" class="button" value="${labelMap.SAVE}" onclick="SAVE_Click()" />
                        <input type="reset" id="RESET" name="RESET" class="button" value="${labelMap.RESET}" />
                        <input type="button" id="CLOSE" name="CLOSE" class="button" value="${labelMap.CLOSE}" onclick="window.history.back()" />                    </th>
                </tr>
            </table>
        </form>
    </body>
</html>
